package pl.com.like.sequoia.dao.security;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;

import pl.com.like.sequoia.dao.GenericDao;
import pl.com.like.sequoia.model.security.User;

public class UserDao extends GenericDao<User, Long> implements IUserDao {

	public UserDao() {
		super(User.class);
	}

	/** {@inheritDoc} */
	@SuppressWarnings("unchecked")
	public User getUser(String username, String password) {
		User loggedUser = null;
		Criteria crit = getCriteria();
		crit.add(Expression.like("login", username));
		if (password != null) {
			crit.add(Expression.like("password", password));

		}
		List<User> users = crit.list();
		if ((users == null) || (users.isEmpty()) || (users.size() > 1)) {
		} else {
			loggedUser = users.get(0);
		}
		return loggedUser;
	}
}
